﻿using System;
using Presenter.Users;

namespace SocialNetworkClient.Pages.User
{
    public partial class SignOut : System.Web.UI.Page, ISignOutView
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["SignOutPresenter"] != null)
            {
                var presenter = Session["SignOutPresenter"] as SignOutPresenter;
                if (presenter != null)
                    presenter.Reload(this);
            }
            else
            {
                Session["SignOutPresenter"] = new SignOutPresenter(this);
            }

            if (EntitySignOut != null)
                EntitySignOut();

            if (Session["Email"] != null && Session["Password"] != null && Session["UserId"] != null)
            {
                Session.Remove("Email");
                Session.Remove("Password");
                Session.Remove("UserId");
            }

            Page.Response.Redirect(@"~/Pages/User/SignIn.aspx");
        }

        #region Implementation of ISignOutView

        public event Action EntitySignOut;

        #endregion
    }
}
